# Maintainer: Norbert Pfeiler <norbert.pfeiler@gmail.com>

_realname=snappy
pkgbase=mingw-w64-${_realname}
pkgname="$MINGW_PACKAGE_PREFIX-${_realname}"
pkgver=1.1.3
pkgrel=1
pkgdesc="A fast C++ compressor/decompressor library (mingw-w64)"
arch=('any')
license=('New BSD License')
url="hhttps://github.com/google/snappy"
depends=("$MINGW_PACKAGE_PREFIX-gcc-libs")
makedepends=("$MINGW_PACKAGE_PREFIX-gcc"
             "make")
checkdepends=("$MINGW_PACKAGE_PREFIX-lzo2"
              "$MINGW_PACKAGE_PREFIX-zlib")
source=(https://github.com/google/snappy/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz
        001-no-undefined.patch
        002-am_prog-ar.patch)
sha256sums=('2f1e82adf0868c9e26a5a7a3115111b6da7e432ddbac268a7ca2fae2a247eef3'
            '3163a8cde8a0aef67498bb70975ff8f2f9b3dd075060c13472ef9b818e771faa'
            '88144991583e9b6cca6f00cfc4926305491601496a952e99e788898553debcc5')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-no-undefined.patch
  patch -p1 -i ${srcdir}/002-am_prog-ar.patch
  autoreconf -fi
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}-${pkgver}/configure \
    --prefix="$MINGW_PREFIX" \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

check() {
  cd "build-${MINGW_CHOST}"
  ./snappy_unittest.exe
}

package() {
  cd "build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
